﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;

namespace PeisongWeb.admin
{
    public partial class priceHistoryList : adminPage
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (hasPermission("CC", 1))
                {
                    if (Request.QueryString["no"] != null)
                    {
                        txt_proNo.Text = Request.QueryString["no"];
                        txt_companyName.Text = Request.QueryString["company"];
                    }
                    rptBind();
                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "index.aspx");
                    return;
                }
               
            }
        }

        void rptBind()
        {
            StringBuilder where = new StringBuilder();
            where.Append("1=1");
            if (txt_proNo.Text.Trim() != "")
                where.AppendFormat("and [productNo] = '{0}'", txt_proNo.Text.Trim());
            if (!string.IsNullOrEmpty(Request.QueryString["bn"]))
                where.AppendFormat(" and [businessNature]='{0}'", Request.QueryString["bn"]);
            if (txt_proName.Text.Trim() != "")
                where.AppendFormat("and [productName] like '%{0}%'", txt_proName.Text.Trim());
            if (txt_companyName.Text.Trim() != "")
                where.AppendFormat("and [companyName] like '%{0}%'", txt_companyName.Text.Trim());

            if (!string.IsNullOrEmpty(Request.QueryString["company"]))
            {
                DataSet ds = logic.priceSeller.select(where.ToString(), "inputDt desc", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);
                AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
                rpt_list.DataSource = ds.Tables[1];
                rpt_list.DataBind();
            }
            else
            {
                DataSet ds = logic.sellerPriceHistory.select(where.ToString(), "inputDt desc", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);
                AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
                rpt_list.DataSource = ds.Tables[1];
                rpt_list.DataBind();
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            rptBind();
        }

        protected void lbtn_Search_Click(object sender, EventArgs e)
        {
            rptBind();
        }
    }
}
